package com.fy.common.util;

public class ObjectUtil {
    /**
     * Object转String
     * @return
     */
    public static String objToString(Object obj) {
        String str = null;
        try{
            if(null != obj){
                str = String.valueOf(obj);
            }
        }catch(Exception e){
            e.printStackTrace();
        }
        return str;
    }

    /**
     * Object转long
     * @param obj
     * @return
     */
    public static long objToLong(Object obj) {
        long value = 0;
        try {
            if (null != obj) {
                value = Long.valueOf(objToString(obj));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return value;
    }

    /**
     * Object转int
     * @param obj
     * @return
     */
    public static int objToInt(Object obj) {
        int value = 0;
        try {
            if (null != obj) {
                value = Integer.valueOf(objToString(obj));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return value;
    }

    /**
     * Object转double
     * @param obj
     * @return
     */
    public static double objToDouble(Object obj) {
        double value = 0;
        try {
            if (null != obj) {
                value = Double.valueOf(objToString(obj));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return value;
    }
}
